<html>

<head>
    <meta charset="utf-8">
    <title>修改投票活动</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/${BasePath}/static/css/headpic.css" media="all" />
    <link rel="stylesheet" href="/${BasePath}/static/layui/css/layui.css" media="all" type="text/css">
    <link rel="stylesheet" href="/${BasePath}/static/css/public.css" media="all" type="text/css"> 
</head>
<body class="childrenBody">
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
	  <legend>修改投票活动</legend>
	</fieldset>
    <form id="activityForm" class="layui-form" lay-filter="example">
    <input type="hidden" name="id" id="id" value="${activity.id!'0'}">
    <input type="hidden" name="backmusic" id="backmusic" value="${activity.backmusic!'/${BasePath}/static/images/backmusic.mp3'}">
        <div class="layui-col-md6 layui-col-xs12">
            <div class="layui-form-item">
                <label class="layui-form-label">投票标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="${activity.title!''}" placeholder="请输入投票标题" class="layui-input"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">背景音乐</label>
                <div class="layui-input-block">
                    <button id="upload" type="button" class="layui-btn">上传音乐</button> 
                    <input id="upfile" style="display: none" type="file" name="upfile"> 
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">可投票次数</label>
                <div class="layui-input-block">
                    <input type="text" name="times" lay-verify="required|number" value="5" readonly class="layui-input realName"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">访问量</label>
                <div class="layui-input-block">
                    <input type="text" name="totalnum" lay-verify="required|number" value="${activity.totalnum!''}" class="layui-input"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <input type="text" placeholder="请输入开始时间" name="startTime" id="date1" lay-verify="required" value="${activity.startTime!''}" readonly class="layui-input userBirthday"> </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                    <input type="text" placeholder="请输入结束时间" name="endTime" id="date2" lay-verify="required" value="${activity.endTime!''}" readonly class="layui-input userBirthday"> </div>
            </div>
             <div class="layui-form-item ">
                <label class="layui-form-label">奖品</label>
                <div class="layui-input-block"> 
                    <#list giftlistall as giftall>
                	<div class="layui-inline selectitem" data-id="${giftall.id}">
                		<img alt="" class="shop-logo" src="${giftall.giftpic}">
                		<div class="money layui-form-item">
                			<div class="layui-inline">${giftall.price}元=${giftall.votenum}点</div>
                		</div>
                	</div>
                	</#list>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" type="button" lay-filter="form">立即提交</button>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript" src="/${BasePath}/static/layui/layui.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/jquery-2.1.0.min.js"></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/ajaxfileupload.js" charset="utf-8" ></script>
    <script type="text/javascript" src="/${BasePath}/static/js/common/popup.js"></script>
    <script type="text/javascript">
    var checked = '${giftlistcheck}';
    if(checked != ""){
    	var arr = checked.split(",");
    	$.each(arr,function(index,i){
    		$(".selectitem").each(function(){
    			if($(this).attr('data-id') == i){
    				$(this).addClass("active");
    			}
    		})
    	})
    }
    $(document).on('click','.selectitem',function(){
    	if($(this).hasClass('active')){
    		$(this).removeClass("active");
    	}
    	else{
    		$(this).addClass("active");
    	}
    })
    layui.use(['form', 'laydate','layer'], function() {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date2'
            ,type: 'datetime'
        });
        form.on('submit(form)', function() {
        	layer.msg('数据保存中', {
					icon:16,
					shade:[0.5,'#333'],
					time:false
			})
        	var arr = [];
        	$(".selectitem.active").each(function(){
        		arr.push($(this).attr("data-id"));
        	})
        	var str=arr.join(",");
        	var data = $('#activityForm').serialize();
                $.ajax({
                    type: "POST",
                    url: "/${BasePath}/activity/saveActivity2?gift="+str,
                    data: data,
                    error: function(request) {
                        layer.msg('系统错误！');
                    },
                    success: function(data) {
                        if(data.code = "1") {
                            layer.msg(data.msg,{time:1000},function(){
                            	window.location.href="/${BasePath}/activity/activityList";
                            })
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            })
    });
    /* 上传背景音乐 */
    $("#upload").on('click', function() {
        $("#upfile").click();
    });
    $("#upfile").on("change", upfile);

    function upfile() {
        var fileSize = $("#upfile")[0].files[0].size;//文件的大小，单位为字节B
        if(fileSize > 10485760) {
            showTips('请上传大小小于10M的音乐');  
        }else{
            $.ajaxFileUpload({
                secureuri: false,
                url: "/${BasePath}/upload/springUpload",
                dataType: "json",
                fileElementId: 'upfile',
                success: function(data) { 
                	showTips('上传成功！',1500,1);
                    $("#upload").attr("src", data.path);
                    $("#backmusic").val(data.path);
                    $("#upfile").on("change", upfile);
                }
            });        	
        }
    }
    </script>
</body>

</html>